// pages/issue/index/index.js
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var user = require('../../../utils/user.js');
var app = getApp();

Page({  

  /**
   * 页面的初始数据
   */
  data: {
    hasLogin: false,
    userInfo:{phone:""},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

    // 判断有没有登陆
    if (app.globalData.hasLogin) {
      let userInfo = wx.getStorageSync('userInfo');
      this.setData({
        userInfo: userInfo,
        hasLogin: true
      }); 
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  goLogin() {
    if (!this.data.hasLogin) {
      wx.navigateTo({
        url: "/pages/auth/login/login"
      });
    }
  },
  goLogin() {
    wx.navigateTo({
      url: "/pages/auth/login/login"
    });
  },  

  bindAddProductInfo: function () {
    // 添加卖的
    if (this.data.hasLogin) {
      let _phone = this.data.userInfo.phone;
      if(_phone > 0){ 
        wx.navigateTo({ 
          url: "/pages/issue/product/product"
        });
      }else{
        wx.navigateTo({
          url: "/pages/auth/mobile/mobile"
        });
      }
    } else {
      wx.navigateTo({
        url: "/pages/auth/login/login"
      });
    };  
  },
  bindAddBuyInfo: function () {
    // 添加求购
    if (this.data.hasLogin) {
      let _phone = this.data.userInfo.phone;
      if(_phone > 0){   
        wx.navigateTo({
          url: "/pages/issue/recycle/recycle"
        }); 
      }else{
        wx.navigateTo({
          url: "/pages/auth/mobile/mobile"
        });
      }
    } else {
      wx.navigateTo({
        url: "/pages/auth/login/login"
      });
    };
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})